<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>路由传参</title>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
    <style>
        ul {
            list-style-type: none;
        }

        li {
            float: left;
            width: 150px;
        }

        li a {
            text-decoration: none;
        }

        .show {
            clear: both;
            margin-top: 50px;
        }
    </style>
</head>

<body>
    <template id="t1">
        <div>
            类型：{{$route.params.category}}<br>
            <h2>{{newsList[$route.params.category-1]}}</h2>
        </div>
    </template>
    <div id="app">
        <div>
            <ul>
                <li>
                    <router-link to="/news/1">今日头条</router-link>
                </li>
                <li>
                    <router-link to="/news/2">体育新闻</router-link>
                </li>
                <li>
                    <router-link to="/news/3">娱乐资讯</router-link>
                </li>
            </ul>
        </div>
        <div class="show">
            <router-view></router-view>
        </div>
    </div>
</body>

</html>
<script>
    var vm = new Vue({
        el:"#app",
        router:new VueRouter({
            routes: [
                {
                    path:"/news/:category",
                    component: {
                        template: "#t1",
                        data() {
                            return {
                                newsList: [
                                    "头条新闻详情",
                                    "体育新闻详情",
                                    "娱乐新闻详情"
                                ]
                            }
                        }
                    }
                }
            ]
        })
    });
</script>